package com.hzit.servlet;

import com.hzit.entity.Classes;
import com.hzit.entity.R;
import com.hzit.service.IClassesService;
import com.hzit.util.ResponseUtil;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/classes")
public class ClassesServlet extends HttpServlet {
	private IClassesService classesService;

	@Override
	public void init() throws ServletException {
		classesService = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext()).getBean(IClassesService.class);
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("application/json;charset=utf8");
		List<Classes> classesList = classesService.findAll();
		ResponseUtil.out(resp, R.ok(classesList));
	}
}
